
* AD and Chávez shares
use "data/inputs/MunicipioData_AD_Chavez.dta", clear


* merge 1968 CCN and MEP shares (congressional)
merge 1:1 estado municipio using "data/inputs/MunicipioData_Congressional1968.dta"
drop _m


* merge 1993 Convergencia and LCR shares (presidential)
merge 1:1 estado municipio using "data/inputs/MunicipioData_OtherParties1993.dta"
drop _m


* log CCN share
gen ln_CCNshare = ln(.002 + CCNshare_Pequenas1968)
gen ln_MEPshare = ln(MEPshare)


* collect correlations
mat outside = J(4, 1, 0)
local i = 1
foreach var of varlist ln_MEPshare ln_CCNshare share_presCONVERGENICA1993 share_presLCR1993 {
cor share_presOFIC1998 `var'
	mat outside[`i',1] = `r(rho)'
	local i = `i' + 1
}


* table
clear
svmat outside


* record parties
gen party = ""
local i = 1
foreach p in ln_MEPshare ln_CCNshare share_presCONVERGENICA1993 share_presLCR1993 {
	replace party = "`p'" if _n == `i'
	local i = `i' + 1
}


* party label
gen partylabel = "MEP" if regexm(party, "MEP")
replace partylabel = "CCN" if regexm(party, "CCN")
replace partylabel = "Convergencia" if regexm(party, "CONVERG")
replace partylabel = "LCR" if regexm(party, "LCR")


* ideology
gen ideology = "Left" if partylabel == "MEP"
replace ideology = "Far right" if partylabel == "CCN"
replace ideology = "Center-left" if partylabel == "Convergencia"
replace ideology = "Left" if partylabel == "LCR"


* year
gen year = "1968, Congressional" if partylabel == "MEP" | partylabel == "CCN"
replace year = "1993, Presidential" if partylabel == "Convergencia" | partylabel == "LCR"


* format correlation
format outside1 %3.2f
tostring outside1, replace usedisplayformat force


* tex 
gen latex = partylabel 
replace latex = latex + " & " + year + " & " + ideology + " & " + outside1
replace latex = latex + " \\"	
replace latex = latex + " \midrule" if _n == 2		
outsheet latex using "tables/TableC1.tex", noquote nonames replace


* End
